define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clients_need/index' + location.search,
                    add_url: 'clients_need/add',
                    edit_url: 'clients_need/edit',
                    del_url: 'clients_need/del',
                    multi_url: 'clients_need/multi',
                    import_url: 'clients_need/import',
                    table: 'clients_need',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'house_status', title: __('House_status'), searchList: {"1":__('House_status 1'),"2":__('House_status 2'),"3":__('House_status 3'),"5":__('House_status 5')}, formatter: Table.api.formatter.status},
                        {field: 'now_status', title: __('Now_status'), searchList: {"1":__('Now_status 1'),"2":__('Now_status 2')}, formatter: Table.api.formatter.status},
                        // {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'goods.name', title: __('Goods.name'), operate: 'LIKE'},
                        {field: 'area_size', title: __('Area_size'), operate: 'LIKE'},
                        {field: 'area', title: __('Area'), operate: 'LIKE'},
                        {field: 'house_type', title: __('House_type'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'clients.name', title: __('Clients.name'), operate: 'LIKE'},
                        {field: 'clients.tel', title: __('Clients.tel'), operate: 'LIKE'},
                        {field: 'tag.title', title: __('Tag.title'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});